/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package daos;

import beans.AfiliadoBean;
import beans.Bean;
import beans.PrestadoraBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author C
 */
public class MSSQLPrestdoraDao extends MSSQLDao implements Dao{

    public MSSQLPrestdoraDao() throws Exception {
    }

    public MSSQLPrestdoraDao(String db) throws Exception {
        super(db);
    }
   
    
    @Override
    public Bean make(ResultSet result) throws Exception {
        PrestadoraBean p= new PrestadoraBean();
        p.setNombre(result.getString("nombre_prestadora")); 
        p.setAccesoWS(result.getString("acceso_ws"));
        
        //System.out.println("+++++++++++++++++++++++++++++++++++    DB " + os.getAccesoWS() );
        
        return p;
    }

    @Override
    public int insert(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void update(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void delete(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<Bean> select(Bean bean) throws Exception {
        ResultSet result;
        List<Bean> prestadoras = new ArrayList<Bean>();
        this.setStatement("get_prestadoras"); // agregar el parametro al procedimiento
        result = this.getStatement().executeQuery();         
        while (result.next()) 
            prestadoras.add(this.make(result));
        return prestadoras;
        
    }

    @Override
    public boolean valid(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Bean get(Bean bean) throws Exception {   
        try{            
            this.setStatement("get_prestadora(?)"); // agregar el parametro al procedimiento       
            this.getStatement().setString(1, ((PrestadoraBean) bean).getNombre()); 
            ResultSet result = this.getStatement().executeQuery();      
            result.next();              
            bean = make(result);                 
        } catch (SQLException ex) {            
            return null;
        } catch (Exception ex2) { throw ex2; }  
        finally { this.destroy(); }
        return bean;        
    }

    @Override
    public long getSize(Bean bean) throws Exception {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
